const router = require('express').Router()
const { Administrator } = require('../utils/db')

// url: /api/admin/register
router.post('/register', (req, res, next) => {
  // 从请求主体中获取传递的用户名与密码
  const { username, password } = req.body
  // 保存到数据库中
  const admin = new Administrator({username, password})
  admin.save().then(data => {
    res.json({
      code: 200,
      data: {
        status: 1,
        message: "register success",
        username: data.username
      }
    })
  }).catch(err => {
    res.json({
      code: -1,
      err
    })
  })
})

module.exports = router